import router from '@/router'
import strong from '@/utils/strong'
import store from '@/store'

router.beforeEach((to,from ,next)=>{
    let token = strong.get('qf-token')

    if(token){
       if(!store.state.permisson.useMens.length){
        store.dispatch('permisson/GETDG')
        .then(()=>{
            next({path: to.path,replace:true,query:to.query})
        })
       }
       else{
        next()
       }
    }else{
        if(to.path==='/login'){
            next()
        }else{
            next({path:'/login'})
        }
    }
})


router.afterEach((to,from)=>{
    // console.log('to---',to)
    // console.log('from---',from)
    let matched = to.matched.filter((item,index) => index>0)
    // console.log('matched--',matched)

    store.commit('mianbao/MUBIAOPATH',matched)
})

export default router
